# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator

from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dwd.tab.dwd_tab_barscan_collect_base_dt import jms_dwd__dwd_tab_barscan_collect_base_dt
from jms.dim.tab.dim_tab_terminal_secret_base import jms_dim__dim_tab_terminal_secret_base
from jms.dwd.tab.dwd_tab_barscan_return_msg_base_dt import jms_dwd__dwd_tab_barscan_return_msg_base_dt
from jms.dwd.tab.dwd_tab_barscan_deliver_base_dt import jms_dwd__dwd_tab_barscan_deliver_base_dt
from jms.dwd.sqs.work_order_duplicate.dwd_project_work_order_new_base_dt import jms_dwd__dwd_project_work_order_new_base_dt
from jms.dim.tab.dim_tab_agent_point_base import jms_dim__dim_tab_agent_point_base
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dwd.oms.dwd_yl_oms_interceptorpiece_base import jms_dwd__dwd_yl_oms_interceptorpiece_base
from jms.dim.dim_mysql_lmdm_sys_tail_dispatch_area_staff import jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area_staff
from jms.time_sensor.time_after_04_45 import time_after_04_45

dm__dm_network_end_dispatch_diff_detail = SparkSubmitOperator(
    task_id='dm__dm_network_end_dispatch_diff_detail',
    pool_slots=4,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='dm__dm_network_end_dispatch_diff_detail_{{ execution_date | date_add(1) | cst_ds }}',
    driver_memory='8G',
    executor_memory='14G',
    executor_cores=8,
    num_executors=40,
    retries=1,
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    conf={'spark.executor.memoryOverhead': 2048,
          'spark.core.connection.ack.wait.timeout': 5000,   #连接等待时长默认60s
          'spark.default.parallelism': 600,
          'spark.locality.wait': 120, #优先将task分配到它要计算的数据所在节点，等待时长
          'spark.driver.maxResultSize': 4, #限制driver计算结果大小，超出报OutOfMemoryError
          'spark.sql.shuffle.partitions': 1200,
          'spark.dynamicAllocation.maxExecutors': 50,  # 动态资源最大扩容 Executor 数
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2',
          },
    jars='hdfs:///scheduler/jms/spark/zyt/store_dispatch_data/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.export.ExportStoreDispatchData',
    application='hdfs:///scheduler/jms/spark/zyt/store_dispatch_data/StoreDispatchData.jar',
    application_args=['{{ execution_date | cst_ds }}'],
    execution_timeout=timedelta(minutes=90),
)

dm__dm_network_end_dispatch_diff_detail << [
    jms_dwd__dwd_tab_barscan_collect_base_dt,
    jms_dim__dim_tab_terminal_secret_base,
    jms_dwd__dwd_tab_barscan_return_msg_base_dt,
    jms_dwd__dwd_tab_barscan_deliver_base_dt,
    jms_dwd__dwd_project_work_order_new_base_dt,
    jms_dim__dim_tab_agent_point_base,
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    time_after_04_45,
    jms_dim__dim_mysql_lmdm_sys_tail_dispatch_area_staff,
    jms_dwd__dwd_yl_oms_interceptorpiece_base
]
